/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            storeMsgManageInfo: {
                storeMsgs: [],
                total: 0,
                records: 1,
                moreCondition: false,
                msgId: '',
                msgFlags: [],
                conditions: {
                    title: '',
                    msgFlag: '',
                    msgId: '',
                    shopId:''
                }
            }
        },
        _initMethod: function () {
            $that._listStoreMsgs(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('store_msg', "msg_flag", function (_data) {
                $that.storeMsgManageInfo.msgFlags = _data;
            });
        },
        _initEvent: function () {
            vc.on('storeMsgManage', 'listStoreMsg', function (_param) {
                $that._listStoreMsgs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listStoreMsgs(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listStoreMsgs: function (_page, _rows) {
                $that.storeMsgManageInfo.conditions.page = _page;
                $that.storeMsgManageInfo.conditions.row = _rows;
                $that.storeMsgManageInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                
                let param = {
                    params: $that.storeMsgManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/shopMsg.listShopMsg',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.storeMsgManageInfo.total = _json.total;
                        $that.storeMsgManageInfo.records = _json.records;
                        $that.storeMsgManageInfo.storeMsgs = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.storeMsgManageInfo.records,
                            dataCount: $that.storeMsgManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddStoreMsgModal: function () {
                vc.emit('addStoreMsg', 'openAddStoreMsgModal', {});
            },
            _openEditStoreMsgModel: function (_storeMsg) {
                vc.emit('editStoreMsg', 'openEditStoreMsgModal', _storeMsg);
            },
            _openDeleteStoreMsgModel: function (_storeMsg) {
                vc.emit('deleteStoreMsg', 'openDeleteStoreMsgModal', _storeMsg);
            },
            //查询
            _queryStoreMsgMethod: function () {
                $that._listStoreMsgs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetStoreMsgMethod: function () {
                $that.storeMsgManageInfo.conditions.title = "";
                $that.storeMsgManageInfo.conditions.msgFlag = "";
                $that.storeMsgManageInfo.conditions.msgId = "";
                $that._listStoreMsgs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.storeMsgManageInfo.moreCondition) {
                    $that.storeMsgManageInfo.moreCondition = false;
                } else {
                    $that.storeMsgManageInfo.moreCondition = true;
                }
            },
        }
    });
})(window.vc);
